package demo1;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.naming.InitialContext;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayer;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.border.EmptyBorder;

import com.sun.glass.ui.TouchInputSupport;


import view2_class.AddBook;

import view2_class.AddStudent;

import view2_class.BorrowRecord;
import view2_class.Search;

import view2_class.DelBook;
import view2_class.Face2;
import view2_class.Search2;

public class View2 extends JFrame {
	JSplitPane jSplitPane;
	JPanel jp1,jp2;
	JPanel jframe;
	JButton search,search2,borrowRecord,addBook,delBook,addStudent;
	JPanel contentPane;
	public View2(){	
		Image icon = Toolkit.getDefaultToolkit().getImage("image/logo2.png");
		setIconImage(icon);//改变LOGO
		
		/*JLabel bg = new JLabel(new ImageIcon("image/view2.jpg"));
		bg.setBounds(0, 0, 450, 350);
		this.getLayeredPane().add(bg, new Integer(Integer.MIN_VALUE));*/
		// 设置背景图片
		
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		
		search  = new JButton("图书搜索");
		search2 =new JButton("用户搜索");
		borrowRecord = new JButton("借书记录");
		addBook = new JButton("新增图书");
		delBook = new JButton("图书注销");
		addStudent = new JButton("新增用户");
		jp1=new JPanel();
		jp1.setBackground(Color.white);
		jp1.add(search);
		jp1.add(search2);
		jp1.add(borrowRecord);
		jp1.add(addBook);
		jp1.add(delBook);
		jp1.add(addStudent);
		
		
		Icon image1=new ImageIcon("image/图书搜索.png");
		Icon image2=new ImageIcon("image/用户搜索.png");
		Icon image3=new ImageIcon("image/借书记录2.png");
		Icon image4=new ImageIcon("image/新增图书.png");
		Icon image5=new ImageIcon("image/图书注销.png");
		Icon image6=new ImageIcon("image/新增用户.png");
		
		search.setFont(new Font("微软雅黑 Light", Font.PLAIN, 20));
		search2.setFont(new Font("微软雅黑 Light", Font.PLAIN, 20));
		borrowRecord.setFont(new Font("微软雅黑 Light", Font.PLAIN, 20));
		addBook.setFont(new Font("微软雅黑 Light", Font.PLAIN, 20));
		delBook.setFont(new Font("微软雅黑 Light", Font.PLAIN, 20));
		addStudent.setFont(new Font("微软雅黑 Light", Font.PLAIN, 20));//设置按钮字体
		
		search.setIcon(image1);
		search2.setIcon(image2);
		borrowRecord.setIcon(image3);
		addBook.setIcon(image4);
		delBook.setIcon(image5);
		addStudent.setIcon(image6);
		
		search.setBackground(new Color(234, 248, 249));
		search2.setBackground(new Color(234, 248, 249));
		borrowRecord.setBackground(new Color(234, 248, 249));
		addBook.setBackground(new Color(234, 248, 249));
		delBook.setBackground(new Color(234, 248, 249));
		addStudent.setBackground(new Color(234, 248, 249));//设置按钮背景为白色
		
		search.setBorderPainted(false);
		search2.setBorderPainted(false);
		borrowRecord.setBorderPainted(false);
		addBook.setBorderPainted(false);
		delBook.setBorderPainted(false);
		addStudent.setBorderPainted(false);//取消按钮边框
		
		/*search.setBounds(160, 10, 160, 50);
		search2.setBounds(160, 80, 160, 50);
		borrowRecord.setBounds(160, 150, 160, 50);
		addBook.setBounds(160, 220, 160, 50);
		delBook.setBounds(160, 290, 160, 50);
		addStudent.setBounds(160, 400, 160, 50);//设置按钮大小，位置*/

		
		jp2=new JPanel();
		jp2.setBackground(Color.white);
		
		jSplitPane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,jp1,jp2);
		//add(jSplitPane);
		jSplitPane.setDividerLocation(200); //分割线的位置  也就是初始位置
		jSplitPane.setOneTouchExpandable(false); //是否可展开或收起，在这里没用
		jSplitPane.setDividerSize(2);//设置分割线的宽度 像素为单位
		jSplitPane.setEnabled(false); //设置分割线不可拖动！！
		this.add(jSplitPane);  //加入到面板中就好
		setBounds(300,200,800,500);
		setVisible(true);
		jSplitPane.setDividerLocation(0.2);// 在1/2处进行拆分
		//按钮触发的事件
		jp1.setOpaque(false);
		jp2.setOpaque(false);
		
		Init(jSplitPane.getRightComponent(),new Face2());
		
		search.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {				
				
				Init(jSplitPane.getRightComponent(),new Search(Book.searchAllBook()));
				
				//用于显示所有图书的界面
			}
		});
		search2.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				Init(jSplitPane.getRightComponent(),new Search2(Student.searchAllStudent()));
				//用于显示所有用户的界面
			}
		});
		borrowRecord.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				Init(jSplitPane.getRightComponent(),new BorrowRecord(Borrow.searchAllBorrowRecord()));
				
				//用于显示所有借书记录的界面
			}
		});
		addBook.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				Init(jSplitPane.getRightComponent(),new AddBook());
				
				//用于添加图书的界面
			}
		});
		delBook.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				Init(jSplitPane.getRightComponent(),new DelBook());
				
				//用于删除图书的界面
			}
		});
		addStudent.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				Init(jSplitPane.getRightComponent(),new AddStudent());
					
				//用于添加学生用户的界面
			}
		});
		setTitle("操作界面");
		setFont(new Font("微软雅黑 Light", Font.PLAIN, 20));
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		SetSwing.setCenter(this);// 使用内部类的静态方法
		setResizable(false);
		setVisible(true);
		setFocusable(true);
		validate();	
		
		
				
	}
	public void Init(Component component,JPanel jp3){
		jSplitPane.remove(component);
		jSplitPane.add(jp3);
		jSplitPane.setDividerLocation(200); //分割线的位置  也就是初始位置
		jSplitPane.setOneTouchExpandable(false); //是否可展开或收起，在这里没用
		jSplitPane.setDividerSize(2);//设置分割线的宽度 像素为单位
		jSplitPane.setEnabled(false); //设置分割线不可拖动！！
		this.add(jSplitPane);  //加入到面板中就好
		setBounds(300,200,800,500);
		SetSwing.setCenter(this);
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		setVisible(true);
		jSplitPane.setDividerLocation(0.2);// 在1/5处进行拆分
		//按钮触发的事件
	}





	public static void main(String[] args) {
		new View2();

	}

	
}